package poker.gui;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JComponent;

import poker.entities.Card;

public class GraphicChips{

	
    ImageIcon chipsImage;
    int playerNumber;
		
	public GraphicChips(int value, int playerNumber) {
		String imagePath="";
		this.playerNumber=playerNumber;
				
		imagePath="image/chips_"+String.valueOf(value)+".png";
		
		chipsImage = new ImageIcon(imagePath);
		
		//rotateImage(playerNumber*90);
		
	}
	//
    
    
    public void rotateImage( int angle) {
    	int w = chipsImage.getIconWidth();
    	int h = chipsImage.getIconHeight();
    	BufferedImage bi = new BufferedImage(w,h,
                          BufferedImage.TYPE_INT_RGB);
    	Graphics bg = bi.createGraphics();
    	((Graphics2D) bg).rotate(Math.toRadians(angle), w/2, h/2);
    	bg.drawImage(chipsImage.getImage(),0,0,w, h,
    			0,0,w, h, null);

    	bg.dispose();//cleans up resources
//    	this.cardImage=bi;
    }

	public ImageIcon getCardImage() {
		return chipsImage;
	}

	public void setCardImage(ImageIcon cardImage) {
		this.chipsImage = cardImage;
	}
	
	//Selon le site de Java:
	//http://download.oracle.com/javase/tutorial/uiswing/components/icon.html#example
	 /**
	   * Resizes an image using a Graphics2D object backed by a BufferedImage.
	   * @param srcImg - source image to scale
	   * @param w - desired width
	   * @param h - desired height
	   * @return - the new resized image
	   */
	  public Image getScaledImage(Image srcImg, int w, int h){
	      BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
	      Graphics2D g2 = resizedImg.createGraphics();
	      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	      g2.drawImage(srcImg, 0, 0, w, h, null);
	      g2.dispose();
	      return resizedImg;
	  }

}
